package com.igame.Controller;

import com.igame.Service.CollectService;

import com.igame.common.Result;
import com.igame.dto.CollectDto;
import com.igame.entity.Collect;
import com.igame.vo.GoodsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin //忽视跨域问题
@RestController
@RequestMapping("/collect")
@Slf4j
public class CollectController {

    @Autowired
    CollectService collectService;

    @PostMapping("/addCollect")
    public Result addCollect(@RequestBody CollectDto collectDto){
        Integer goodsId = Integer.valueOf(collectDto.getGoodsId());
        Integer userId = Integer.valueOf(collectDto.getUserId());
        return collectService.addCollect(userId,goodsId);
    }

    @PostMapping("/deleteCollect")
    public Result deleteCollect(@RequestBody CollectDto collectDto){
        Integer goodsId = Integer.valueOf(collectDto.getGoodsId());
        Integer userId = Integer.valueOf(collectDto.getUserId());
        return collectService.deleteCollect(userId,goodsId);
    }

    @PostMapping("/selectCollect")
    public Result selectCollect(@RequestBody CollectDto collectDto){
        Integer goodsId = Integer.valueOf(collectDto.getGoodsId());
        Integer userId = Integer.valueOf(collectDto.getUserId());
        return collectService.selectCollect(userId,goodsId);
    }

    @PostMapping("/myCollection")
    public Result<List<GoodsVo>> myCollection(@RequestBody Integer id){
        return collectService.getMyCollection(id);
    }
}
